package cc.magicjson.mall.order.infrastructure.anticorruption;


import cc.magicjson.mall.common.domain.ProductId;
import cc.magicjson.mall.order.domain.model.Money;
import cc.magicjson.mall.order.infrastructure.feign.ProductServiceClient;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.Currency;

/**
 * ProductPriceTranslator 防腐层
 * 用于转换外部服务（商品服务）的数据到领域模型
 */
@Component
public class ProductPriceTranslator {
	private final ProductServiceClient productServiceClient;

	public ProductPriceTranslator(ProductServiceClient productServiceClient) {
		this.productServiceClient = productServiceClient;
	}

	public Money translatePrice(ProductId productId) {
		// 调用商品服务获取价格，并转换为 Money 值对象
		BigDecimal price = productServiceClient.getProductPrice(productId.id());
		return new Money(price, Currency.getInstance("USD"));
	}
}